package com.example.xianji.adapter;

import java.util.ArrayList;

import com.example.xianji.Contant;
import com.example.xianji.R;
import com.example.xianji.bean.ZiZhi;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.listener.SimpleImageLoadingListener;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class MyZiZhi_Adapter extends BaseAdapter {
    private Context context;
    private ArrayList<ZiZhi> list;


    public MyZiZhi_Adapter(Context context, ArrayList<ZiZhi> list) {
        super();
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Holder mHolder;
        if (convertView == null) {
            mHolder = new Holder();
            convertView = View.inflate(context, R.layout.zizhi_item_layout, null);
            mHolder.zizhi_image = (ImageView) convertView.findViewById(R.id.zizhi_image);
            mHolder.zizhi_name = (TextView) convertView.findViewById(R.id.zizhi_name);
            convertView.setTag(mHolder);
        }
        mHolder = (Holder) convertView.getTag();
        ImageLoader.getInstance().displayImage(Contant.chakan_renzheng + list.get(position).getPath() + list.get(position).getName(), mHolder.zizhi_image, new SimpleImageLoadingListener() {

            @Override
            public void onLoadingComplete(String imageUri, View view,
                                          Bitmap loadedImage) {
                super.onLoadingComplete(imageUri, view, loadedImage);
                ImageView imageview = (ImageView) view;
                imageview.setImageBitmap(loadedImage);
            }


        });
        if (list.get(position).getTitle().length() == 0) {
            mHolder.zizhi_name.setVisibility(View.GONE);
        } else {
            mHolder.zizhi_name.setVisibility(View.VISIBLE);
            mHolder.zizhi_name.setText(list.get(position).getTitle());
        }
        return convertView;
    }

    class Holder {
        TextView zizhi_name;
        ImageView zizhi_image;
    }
}
